package com.sen.common.utils.net;

import org.apache.commons.io.FilenameUtils;

/**
 * 
 * @author sen
 */
public enum MimeMapper {

	TXT("text/plain"), 
	PDF("application/pdf"),
	DOC("application/msword"), 
	XLS("application/msexcel"), 
	CSV("text/comma-separated-values"), 
	PPT("application/mspowerpoint"),
	RAR("application/rar"), 
	ZIP("application/zip"),
	UNKNOWN("application/unknown");

	private String contentType;

	private MimeMapper(String contentType) {
		this.contentType = contentType;
	}

	public String getContentType() {
		return contentType;
	}

	public static MimeMapper fromExtension(String fileFullName) {
		return getMime(FilenameUtils.getExtension(fileFullName));
	}

	public static MimeMapper getMime(String mimeType) {
		if (TXT.toString().equalsIgnoreCase(mimeType)) {
			return TXT;
		} else if (PDF.toString().equalsIgnoreCase(mimeType)) {
			return PDF;
		} else if (DOC.toString().equalsIgnoreCase(mimeType)) {
			return DOC;
		} else if (XLS.toString().equalsIgnoreCase(mimeType)) {
			return XLS;
		} else if (CSV.toString().equalsIgnoreCase(mimeType)) {
			return CSV;
		} else if (PPT.toString().equalsIgnoreCase(mimeType)) {
			return PPT;
		} else if (RAR.toString().equalsIgnoreCase(mimeType)) {
			return RAR;
		} else if (ZIP.toString().equalsIgnoreCase(mimeType)) {
			return ZIP;
		} else {
			return UNKNOWN;
		}
	}
}
